<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\main\MainController as main;
use App\Http\Controllers\Controller;
use DB;

class GoodsSearchController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getSearch(Request $request)
    {
        // 接收用户搜索信息
        
        $search = ($request -> only('search')['search'] ? $request -> only('search')['search'] : '');
        $request -> session() -> put('search',$search);
        $desc = ($request -> only('desc')['desc'] ? $request -> only('desc')['desc'] : 'goods_id');
        $order = ($request -> only('order')['order'] ? $request -> only('order')['order'] : 'asc');

        // dd(session('search'));
        // 调用搜索方法
        $data = main::SearchGoods($search,$desc,$order);
        // 计算搜索到的数组个数
        $count = count($data);
        // dd($data);
        return view('/home/GoodsSearch/index',['data'=>$data,'search'=>$search,'count'=>$count]);
    }

   
}
